package com.workcell.workdata.xthings.dao.impl;

import cn.hutool.core.util.StrUtil;
import com.workcell.workdata.xthings.dao.InformationDao;
import lombok.RequiredArgsConstructor;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@RequiredArgsConstructor
public class InformationDaoImpl implements InformationDao {
    private final JdbcTemplate jdbcTemplate;
    public static final String DEVICE_TABLE_PREFIX = "t_base_";

    /**
     * 查询指定前缀的表
     * @param tableNamePrefix 表前缀
     * @return 指定前缀的表的集合
     */
    @Override
    public List<String> showTables(String tableNamePrefix) {
        String patternSql = "show tables like '{}%'";
        String sql = StrUtil.format(patternSql, tableNamePrefix);
        return jdbcTemplate.query(sql, (resultSet, i) -> resultSet.getString(1));
    }

    @Override
    public List<String> deviceTableList() {
        return showTables(DEVICE_TABLE_PREFIX);
    }
}
